import http from './http'
import { CancelToken } from 'axios'
// 专门写与用户业务相关的接口
export const loginApi = (params: ILoginParams): RS<ILoginResponse> => http.post('/admin/login', params)

export const getUserInfoApi = (): RS<IUserInfoResponse> => http.get('/admin/info')

export const getUserListApi = (params: IUserListParams, token: CancelToken): TS<UserList> => http.get('/admin/list', { params, cancelToken: token });

export const registerUserApi = (params: IUserModel): RS<UserList> => http.post('/admin/register', params)

export const getUserInfoByIdApi = (id: number): RS<UserList> => http.get(`/admin/${id}`);

export const updateUserInfoApi = (params: IUserModel): RS<UserList> => http.post(`/admin/update/${params.id}
`, params)

export const getAllRoleListApi = (): RS<IRoleModel[]> => http.get('/role/listAll')

export const getUserRoleListApi = (adminId: number): RS<IRoleModel[]> => http.get(`/admin/role/${adminId}`)

export const allocUserRoleApi = (params: { adminId: number, roleIds: number[] }): RS<any> => http.post(`/admin/role/update?adminId=${params.adminId}&roleIds=${params.roleIds.join(',')}`)